<?php

$installer = $this;
/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */

$installer->startSetup();

$installer->run("
DROP TABLE IF EXISTS {$this->getTable('digg/digg')};
CREATE TABLE IF NOT EXISTS {$this->getTable('digg/digg')} (
    `product_id` int(10) unsigned NOT NULL,
    `digg_num` int(11) unsigned NOT NULL,
     UNIQUE KEY `UNQ_DIGG_PRODUCT` (`product_id`),
     CONSTRAINT `FK_DIGG_PRODUCT_ENTITY` FOREIGN KEY (`product_id`) REFERENCES `{$installer->getTable('catalog_product_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='digg';

DROP TABLE IF EXISTS {$this->getTable('digg/digg_product')};
CREATE TABLE IF NOT EXISTS {$this->getTable('digg/digg_product')} (
    `product_id` int(10) unsigned NOT NULL,
    `remote_addr` int(11) NOT NULL,
    `customer_id` int(10) unsigned default NULL,
    `visitor_id` bigint(20) unsigned default NULL,
    `creation_time` datetime default NULL,
    UNIQUE KEY  `UNQ_DIGG_PRODUCT_IP` (`product_id`,`remote_addr`), 
    CONSTRAINT `FK_DIGG_PRODUCT_PRODUCT_ENTITY` FOREIGN KEY (`product_id`) REFERENCES `{$installer->getTable('catalog_product_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='product digg';
");
$installer->endSetup();
